
#ifndef _HTML_LINK_H
#define _HTML_LINK_H


/*
 *
 * the node type in html file ,including start_tag,end_tag,comment,text, the comment is not what we want ,so we do not deal with comment,
 * just ignore it;
 */
enum Node_type{
	start_tag,end_tag,text,root//comment is thrown because we shall not to deal with comments
};

/*
 * the attribute of tags
 */
struct Attr_node{
	char *name;
	char *value;
	struct Attr_node *next;
};

/*
 * a html file include many node which includes tart_tag, end_tag,comment,and text,so ,we can describe a html file uing by a linked list,
 * a Html_node is a node in the linked list
 */

struct Html_node{
	enum Node_type node_type; /*the node type*/
	int name_index;/*if is a tag,the index in the array tags*/
	struct Attr_node *attr; /* if node_type is a start_tag , the attr is not null; */
	char   *text_ptr; /* if node_type is a text , the text is not null */

	struct Html_node *next;
};



/*
 * html tokens storing in the static array
 */
extern char * tags[];

/*
 * deal with the attributes of a tag, and return a new pointer pointe to new cursor of html file
 */
char *process_attr(char *ptr,struct Html_node **node);


/*
 * the function of dealing withd text in html file
 */
char *process_text(char *s,struct Html_node **html_node);



/*
 * the function of dealing with start tags in html file
 */
char *process_start_tag(char *s,struct Html_node **html_node);



/*
 * the function of dealing with end tags in html file
 */
char *process_end_tag(char *s,struct Html_node **html_node);



/*
 * the funciton of dealing with comments in thml file
 */
char *process_comment(char *ptr);



/*
 *check a token whether a valid token 
 */
int valid_token(char *s);



/*
 *
 * change a string to lower string
 */
static int tolower_str(char *s);




/*
 * the function of generating a linked list with html node
 */
void genera_link_list(struct Html_node **root,char *s);




/*
 * print the html_node int linked list
 * 
 */
void html_linkedlist_tostring(struct Html_node *root);

/*
	free the memory of the Html_node linklist
 */
void destroy(struct Html_node *root);
#endif
